Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly check URL pathname with Cloudflare adapter #8733

Merged
merged 11 commits into from
Jan 30, 2023
Merged

fix: correctly check URL pathname with Cloudflare adapter #8733

merged 11 commits into from
Jan 30, 2023

Conversation

eltigerchino
Copy link
Member

@eltigerchino eltigerchino commented Jan 26, 2023

fixes #8708
fixes #8736

I noticed a discrepancy where trailing slashes would be removed before checking if the file exists in manifest.prerendered.

This caused the pages with trailing slashes to never be found in the manifest.

Hopefully this fixes the issue for prerendered trailing slash pages that go through the Cloudflare worker.

Pages that manage to fit in the 100 rule limit for _routes.json do not go through the worker so they don't have this issue.

EDIT: expanded the scope of the PR to fix the URI encoding issue mismatch as well. It used to check the encoded pathname against the decoded paths in the manifest.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

@changeset-bot
Copy link

changeset-bot bot commented Jan 26, 2023

🦋 Changeset detected

Latest commit: 84de0dd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/adapter-cloudflare Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@eltigerchino eltigerchino changed the title fix: check prerendered files with trailing slash fix: cloudflare adapter prerendered files with trailing slash Jan 26, 2023
@eltigerchino eltigerchino changed the title fix: cloudflare adapter prerendered files with trailing slash fix: correctly check pathname for Cloudflare adapter prerendered pages Jan 26, 2023
@eltigerchino eltigerchino changed the title fix: correctly check pathname for Cloudflare adapter prerendered pages fix: correctly check pathname in Cloudflare adapter Jan 26, 2023
@eltigerchino eltigerchino changed the title fix: correctly check pathname in Cloudflare adapter fix: correctly check URL pathname in Cloudflare adapter Jan 26, 2023
Comment on lines 51 to 54
const filename = stripped_pathname.substring(1);
if (filename) {
is_asset = manifest.assets.has(filename) || manifest.assets.has(filename + '/index.html');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could there theoretically be an asset named index.html? What was the reason for changing this?

Copy link
Member Author

@eltigerchino eltigerchino Jan 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could there theoretically be an asset named index.html?

If a dev decides to include one in /static I suppose. It helps if someone navigates to that route.
This check was already there previously, but I suppose it's good to have it since the worker has to handle all file routing.

What was the reason for changing this?

I thought it would be a small optimisation, although I'm unsure if it has an impact.

If the url is https://test.com/, then the resulting filename would be ''. This addition helps skip the manifest check for an empty string.

Co-authored-by: Rich Harris <hello@rich-harris.dev>
@eltigerchino eltigerchino changed the title fix: correctly check URL pathname in Cloudflare adapter fix: correctly check URL pathname with Cloudflare adapter Jan 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants